use solutiont8::*;

pub fn find_max_prime_factor(number: u128) -> u128 {
    if is_prime(number) {
        return number;
    }
    max_prime_factor(number)
}

#[inline(always)]
fn max_prime_factor(number: u128) -> u128 {
    if number < 2 {
        return number;
    }
    let mut factor = pollard_rho(number);
    while !is_prime(factor) {
        factor = pollard_rho(factor);
    }

    let other_factor = number / factor;
    if is_prime(other_factor) {
        other_factor.max(factor)
    } else {
        max_prime_factor(other_factor).max(factor)
    }
}

// pub fn is_prime_128(n: u128) -> bool {
//     if n == 2 || n == 3 {
//         return true;
//     } else if n <= 1 || n % 2 == 0 || n % 3 == 0 {
//         return false;
//     }
//     let mut i = 5;
//     while i * i <= n {
//         if n % i == 0 || n % (i + 2) == 0 {
//             return false;
//         }
//         i += 6;
//     }
//     true
// }

// pub fn find_max_prime_factor(number: u128) -> u128 {
//     if number < 2 || is_prime(number) { 
//         return number;
//     }
//     let mut factor = pollard_rho(number);
//     while !is_prime(factor) {
//         factor = pollard_rho(factor);
//     }
// 
//     let other_factor = number / factor;
//     if is_prime(other_factor) {
//         other_factor.max(factor)
//     } else {
//         find_max_prime_factor(other_factor).max(factor)
//     }
// }